package com.bcu.alumnus.repo;

import com.bcu.alumnus.entity.Apply;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface ApplyRepository extends JpaRepository<Apply,Integer>, JpaSpecificationExecutor {

    List<Apply> getApplyByApplyActivityIdAndApplyStatus(String ApplyActivityId,String ApplyStatus);

    List<Apply> getApplyByApplyId(int ApplyId);

    List<Apply> getApplyByApplyUserId(String ApplyUserId);

    List<Apply> getApplyByApplyUserIdAndApplyStatus(String ApplyUserId,String ApplyStatus);

    List<Apply> getApplyByApplyActivityId(String activityId);

    int countApplyByApplyActivityId(String ApplyActivityId);

    int countApplyByApplyActivityIdAndApplyStatus(String ApplyActivityId,String ApplyStatus);

    @Transactional
    @Modifying
    @Query(value = "update Apply set applyStatus=1 where applyActivityId=?1 and applyUserId=?2")
    int updateApplyStatusByApplyActivityIdAndApplyUserId(String ApplyActivityId,String ApplyUserId);

}
